export namespace SeriesValDataList {
    export interface IDataItem {
        value: number | string;
    }
    export type TDataItem = number | string | IDataItem;
    export type TDataList = Array<TDataItem>;
}

export class SeriesValDataList {
    private max: number = NaN;
    private min: number = NaN;
    public readonly dataList: SeriesValDataList.TDataList;
    public readonly valList: number[];

    constructor(dataList: SeriesValDataList.TDataList) {
        this.dataList = dataList;
        this.valList = dataList.map((item) => {
            const val = this.getValueFromDataItem(item);
            if (isNaN(this.min) || this.min > val) {
                this.min = val;
            }
            if (isNaN(this.max) || this.max < val) {
                this.max = val;
            }
            return val;
        });
    }

    public getValueFromDataItem(dataItem: SeriesValDataList.TDataItem): number {
        if (typeof dataItem === "object") {
            return parseFloat(dataItem.value as string);
        }
        return parseFloat(dataItem as string);
    }

    public getMax(): number {
        return this.max;
    }

    public getMin(): number {
        return this.min;
    }
}
